<template>
  <div class="wrapper">
		<div class="header">罗大锤</div>
		<div class="content">
			<div class="friend_img">
				<img :src="currentMemberData.Image" alt="">
			</div>
			<div class="user_info">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">账号</span>
							<span class="items_text">{{currentMemberData.To_Account}}</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="user_info">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">个性签名</span>
							<span class="items_text">{{currentMemberData.SelfSignature}}</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="user_info">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">昵称</span>
							<span class="items_text">{{currentMemberData.Nick}}</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="user_info">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">性别</span>
							<span class="items_text">{{currentMemberData.Gender}}</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="user_info">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">生日</span>
							<span class="items_text">{{timeFormat(currentMemberData.birthDay)}}</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="user_info">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">地区</span>
							<span class="items_text">{{currentMemberData.location}}</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="user_info"  v-show="isTrue()">
					<div class="user_underline">
						<div class="items_left">
							<span class="items_title">设置角色</span>
							<span class="items_text">
								<input type="radio" name="part" :checked="currentMemberPart == 'Admin'" value="Admin">管理员
								<input type="radio" name="part" :checked="currentMemberPart == 'Member'" value="Member">成员
							</span>
						</div>
						<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
					</div>
			</div>
			<div class="details_btn">
				<button @click="deleteGroupMember()" class="color_green" v-show="isKick()">踢出群组</button>
				<button @click="modifyGroupMemberRole()" class="color_green" v-show="isTrue()">修改角色</button>
				<!-- <button class="color_green">发送消息</button>
				<button class="color_green">加为好友</button> -->
			</div>
		</div>
	</div>
</template>

<script>
import $ from 'jquery'
import Client from '../../config/common'
	export default {
		data () {
			return {
				currentMemberId: null,
				currentMemberPart: null,
				currentMemberData: {},
				currentGroupId: null,
				loginInfo: {},
				loginPart: '',
				currentGroupType: ''
				
			}
		},
		created () {

			// 登录初始化
    		this.initLogin();
			
		},
		methods: {

			// 登录初始化
			initLogin() {
				Client.login(this.getLoginInfo);
			},

			// 获得登录成功信息
			getLoginInfo(loginInfo){
				// 将 登录信息保存在 vue的data里
				this.loginInfo = loginInfo;
				Client.log("登录成功获取登录信息-start");
				Client.log(loginInfo);
				Client.log("登录成功获取登录信息-end");

				// 设置当前的成员ID

				this.currentMemberId = Client.getQueryString("currentMemberId");

				// 获取登录人的角色
				this.loginPart = Client.getQueryString("loginPart");

				// 设置查看详情信息的成员角色
				this.currentMemberPart = Client.getQueryString("currentMemberPart");

				// 当前群组的类型
				this.currentGroupType = Client.getQueryString("groupType");

				// 获得当前群组ID
				this.currentGroupId = Client.getQueryString("currentGroupId");
				console.log(11111111);
				console.log(this.currentMemberPart);
				console.log(this.loginPart);
				console.log(11111111);
				if(this.currentMemberId && this.currentMemberPart && this.loginPart){

					// 获取群成员详情
					this.searchProfileByUserId();
				}
				// console.log(this.currentMemberId);
				
			},
			// 是否可踢人
			isKick() {
				let isTrue = false;
				if( this.currentMemberPart != 'Owner' && this.loginPart == 'Owner' ) {
					if( this.loginInfo.identifier != this.currentMemberData.To_Account ) {
						if(this.currentGroupType == 'Public' || this.currentGroupType == 'Private' || this.currentGroupType == 'ChatRoom') {
							isTrue = true;
						}
					}
				}
				return isTrue;
			},

			// 是否修改角色
			isTrue() {
				//  (currentGroupType == 'Public' || currentGroupType == 'ChatRoom')
				let bool = false;
				if( this.currentMemberPart != 'Owner' && this.loginPart == 'Owner' ){
					if(this.loginInfo.identifier != this.currentMemberData.To_Account){
						if(this.currentGroupType == 'Public' || this.currentGroupType == 'ChatRoom') {
							bool = true;
						}
					}
				}
				return bool;
			},

			// 时间格式化
			timeFormat(times) {   
    		return new Date(parseInt(times) * 1000).toLocaleString().replace(/\//g, "-"); 
			},

			//删除群组成员
			deleteGroupMember() {
					if (!confirm("确定移除该成员吗？")) {
							return;
					}
					var options = {
							'GroupId': this.currentGroupId,
							//'Silence': $('input[name="dgm_silence_radio"]:checked').val(),//只有ROOT用户采用权限设置该字段（是否静默移除）
							'MemberToDel_Account': [this.currentMemberId]
					};
					webim.deleteGroupMember(
							options,
							function (resp) {
									//在表格中删除对应的行
									// $('#get_group_member_table').bootstrapTable('remove', {
									// 		field: 'Member_Account',
									// 		values: [$('#dgm_account').val()]
									// });
									// $('#delete_group_member_dialog').modal('hide');
									alert('移除群成员成功');
							},
							function (err) {
									alert(err.ErrorInfo);
							}
					);
			},

			//修改群组成员角色
			modifyGroupMemberRole() {
					let That = this;
					var role_en = $('input[name="part"]:checked').val();
					var role_zh = webim.Tool.groupRoleEn2Ch(role_en);
					var options = {
							'GroupId': this.currentGroupId,
							'Member_Account': this.currentMemberData.To_Account,
							'Role': role_en,
					};
					Client.log(options);
				
					webim.modifyGroupMember(
							options,
							function (resp) {
								console.log("修改群角色成功-start");
								console.log(resp);
								console.log("修改群角色成功-start");
								That.$router.go(-1);
									//在表格中修改对应的行
									/* $('#get_group_member_table').bootstrapTable('updateRow', {
											index: $('#mgm_sel_row_index').val(),
											row: {
													Role: role_zh
											}
									});
									$('#modify_group_member_dialog').modal('hide'); */
									alert('修改群成员角色成功');
							},
							function (err) {
									alert(err.ErrorInfo);
							}
					);
			},

			// 获取群成员详情
			//搜索用户
			searchProfileByUserId() {
					let That = this;
					if (this.currentMemberId.length == 0) {
							alert('请输入用户ID');
							return;
					}

					if (webim.Tool.trimStr(this.currentMemberId).length == 0) {
							alert('您输入的用户ID全是空格,请重新输入');
							return;
					}

					let tag_list = [
							"Tag_Profile_IM_Nick",//昵称
							"Tag_Profile_IM_Gender",//性别

							"Tag_Profile_IM_BirthDay",//生日
							"Tag_Profile_IM_Location", //所在地
							"Tag_Profile_IM_SelfSignature", //个性签名

							"Tag_Profile_IM_AllowType",//加好友方式
							"Tag_Profile_IM_Image"//头像
					];
					let options = {
							'To_Account': [this.currentMemberId],
							'TagList': tag_list
					};

					webim.getProfilePortrait(
									options,
									function (resp) {
											let data = [];
											if (resp.UserProfileItem && resp.UserProfileItem.length > 0) {
													for (let i in resp.UserProfileItem) {
															let to_account = resp.UserProfileItem[i].To_Account;
															let nick = null, gender = null, allowType = null,imageUrl=null, birthDay = null, location = null, SelfSignature = null;
															for (let j in resp.UserProfileItem[i].ProfileItem) {
																	switch (resp.UserProfileItem[i].ProfileItem[j].Tag) {
																			case 'Tag_Profile_IM_SelfSignature':
																					SelfSignature = resp.UserProfileItem[i].ProfileItem[j].Value;
																					break;
																			case 'Tag_Profile_IM_Nick':
																					nick = resp.UserProfileItem[i].ProfileItem[j].Value;
																					break;
																			case 'Tag_Profile_IM_Gender':
																					switch (resp.UserProfileItem[i].ProfileItem[j].Value) {
																							case 'Gender_Type_Male':
																									gender = '男';
																									break;
																							case 'Gender_Type_Female':
																									gender = '女';
																									break;
																							case 'Gender_Type_Unknown':
																									gender = '未知';
																									break;
																					}
																					break;
																			case 'Tag_Profile_IM_AllowType':
																					switch (resp.UserProfileItem[i].ProfileItem[j].Value) {
																							case 'AllowType_Type_AllowAny':
																									allowType = '允许任何人';
																									break;
																							case 'AllowType_Type_NeedConfirm':
																									allowType = '需要确认';
																									break;
																							case 'AllowType_Type_DenyAny':
																									allowType = '拒绝任何人';
																									break;
																							default:
																									allowType = '需要确认';
																									break;
																					}
																					break;
																			case 'Tag_Profile_IM_Image':
																					imageUrl = resp.UserProfileItem[i].ProfileItem[j].Value;
																					break;
																			case 'Tag_Profile_IM_BirthDay':
																					birthDay = resp.UserProfileItem[i].ProfileItem[j].Value;
																					break;
																			case 'Tag_Profile_IM_Location':
																					location = resp.UserProfileItem[i].ProfileItem[j].Value;
																					break;
																	}
															}
															data.push({
																	'To_Account': to_account,
																	'Nick': webim.Tool.formatText2Html(nick),
																	'Gender': gender,
																	'AllowType': allowType,
																	'Image': imageUrl,
																	"birthDay": birthDay,
																	"SelfSignature": SelfSignature,
																	"location": location,
															});
													}
													Client.log("成功获取个人资料-start");
													Client.log(resp);
													Client.log(data);

													// 保存个人信息到data数据中
													That.currentMemberData = data[0];
													Client.log("成功获取个人资料-end");
											}

											// $('#search_profile_table').bootstrapTable('load', data);

									},
									function (err) {
											alert(err.ErrorInfo);
									}
					);
			}
			
			
		}
	}
  
</script>

<style lang="scss">
	@import '../../style/group_member_detail';
	
</style>
